package com.kotlin.base.widgets

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.AnimationDrawable
import android.view.Gravity
import android.widget.ImageView
import com.kotlin.base.R
import org.jetbrains.anko.find

/**
 * @author Mr.Wang
 * @version v0.3.6
 * @time 2018/3/12
 * @describe
 */
class ProgressLoading private  constructor(context: Context?, themeResId: Int) : Dialog(context, themeResId) {
    companion object {
        private lateinit var mDialog:ProgressLoading
        private var animationDrawable:AnimationDrawable? = null

        fun create(context: Context?):ProgressLoading{
            mDialog = ProgressLoading(context, R.style.LightProgressDialog)
            mDialog.setContentView(R.layout.progerss_dialog)
            mDialog.setCancelable(true)
            mDialog.setCanceledOnTouchOutside(false)
            mDialog.window.attributes.gravity = Gravity.CENTER

            var lp = mDialog.window.attributes
            lp.dimAmount = 0.2f
            mDialog.window.attributes = lp

            val loadingView  = mDialog.find<ImageView>(R.id.iv_loading)
//            animationDrawable = loadingView.background as AnimationDrawable

            return  mDialog
        }
    }

    fun showLoading(){
        super.show()
//        animationDrawable?.start()
    }

    fun hideLoading(){
        super.hide()
//        animationDrawable?.stop()
    }
}